package org.telegram.bot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.telegram.bot.domain.BotInfo;
import org.telegram.bot.domain.BotKeyboard;
import org.telegram.bot.service.IBotInfoService;

import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 机器人信息Controller
 *
 * @author wyx
 * @date 2023-05-29
 */
@RestController
@RequestMapping("/bot/botinfo")
@Slf4j
public class BotInfoController extends BaseController
{
    @Autowired
    private IBotInfoService botInfoService;

    /**
     * 查询机器人信息列表
     */
    @PreAuthorize("@ss.hasPermi('bot:botinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BotInfo botInfo)
    {
        startPage();
        List<BotInfo> list = botInfoService.selectBotInfoList(botInfo);
        return getDataTable(list);
    }

    /**
     * 导出机器人信息列表
     */
    @PreAuthorize("@ss.hasPermi('bot:botinfo:export')")
    @Log(title = "机器人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BotInfo botInfo)
    {
        List<BotInfo> list = botInfoService.selectBotInfoList(botInfo);
        ExcelUtil<BotInfo> util = new ExcelUtil<BotInfo>(BotInfo.class);
        util.exportExcel(response, list, "机器人信息数据");
    }

    /**
     * 获取机器人信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('bot:botinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(botInfoService.selectBotInfoById(id));
    }

    /**
     * 新增机器人信息
     */
    @PreAuthorize("@ss.hasPermi('bot:botinfo:add')")
    @Log(title = "机器人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BotInfo botInfo)
    {
        return toAjax(botInfoService.insertBotInfo(botInfo));
    }

    /**
     * 修改机器人信息
     */
    @PreAuthorize("@ss.hasPermi('bot:botinfo:edit')")
    @Log(title = "机器人信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping
    public AjaxResult edit(@RequestBody BotInfo botInfo) {
        return toAjax(botInfoService.updateBotInfo(botInfo));
    }

    /**
     * 删除机器人信息
     */
    @PreAuthorize("@ss.hasPermi('bot:botinfo:remove')")
    @Log(title = "机器人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(botInfoService.deleteBotInfoByIds(ids));
    }
    
    /**
     * 发送按钮消息测试
     */
    @PostMapping("/send")
    public AjaxResult add(@Validated @RequestBody BotKeyboard keyboard)
    {
        return toAjax(botInfoService.sendMessageTest(keyboard));
    }
    
}
